package controller;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.JDialog;
import javax.swing.JFrame;

import user.CurrentUser;
import autoschedule.ui.AutoScheduleDeskTop;
import autoteam.Local;
import autoteam.ui.AutoTeamDeskTop2;

/**
 * RSMSController provides functionality to switch between the different frames
 * used by the RSMS application
 * 
 * @author Benjamin Landers
 * @version %Revision$, $Date: 2010/10/17 2:40 $
 */
public class RSMSController
{

	private JFrame activeFrame = null;
	private JFrame inactiveFrame = null;

	private static CurrentUser curUser;
	private static String curSport;

	// Measure sizeScreen
	private static final Toolkit sizer = Toolkit.getDefaultToolkit(); 
	private static final Dimension screenSize = sizer.getScreenSize();

	public RSMSController()
	{
		// pass << wtf?
	}

	public RSMSController(CurrentUser curUser)
	{
		this.curUser = curUser;
	}

	public void toggle()
	{
		JFrame temp = this.activeFrame;
		Rectangle bounds = temp.getBounds();
		this.inactiveFrame.setBounds(bounds);
		this.setActiveFrame(this.inactiveFrame);
		this.setInactiveFrame(temp);

	}

	public void setActiveFrame(JFrame frame)
	{
		this.activeFrame = frame;
		this.activeFrame.setVisible(true);
	}

	public void setInactiveFrame(JFrame frame)
	{
		this.inactiveFrame = frame;
		this.inactiveFrame.setVisible(false);
	}

	public JFrame getActiveFrame()
	{
		return activeFrame;
	}

	public void replaceActiveFrameAndLogout(JFrame frame)
	{
		replaceActiveFrame(frame);
		// Add logout code here for killing a user session
	}

	public void replaceActiveFrame(JFrame frame)
	{
		this.activeFrame.dispose();
		setActiveFrame(frame);
	}

	public static void main(String[] args)
	{
		// TODO Auto-generated method stub
		String language;
		String country;
		language = new String("en");
		country = new String("US");
		Local.initialize(language, country);

		RSMSController controller = new RSMSController();
		controller.setActiveFrame(new AutoTeamDeskTop2(controller));
		controller.setInactiveFrame(new AutoScheduleDeskTop(controller));

	}

	public static void resizeActiveFrame(JFrame frame, boolean setToFullScreen)
	{
		Dimension resize = frame.getPreferredSize();

		frame.setSize(resize);
		frame.setLocation
		(
			(screenSize.width - resize.width) / 2,
			(screenSize.height - resize.height) / 2
		);

		if (setToFullScreen)
		{
			frame.setExtendedState(Frame.MAXIMIZED_BOTH);
		}
	}
	
	public static void resizeDialog(JDialog dialog)
	{
		Dimension resize = dialog.getPreferredSize();

		dialog.setSize(resize);
		dialog.setLocation
		(
			(screenSize.width - resize.width) / 2,
			(screenSize.height - resize.height) / 2
		);

	}

	public CurrentUser getCurUser()
	{
		return curUser;
	}
	
	public void setCurSport(String Sport)
	{
		curSport = Sport;
	}
	
	public String getCurSport()
	{
		return curSport;
	}



}
